/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pa165.languageschoolpersistence.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Elena Medvedeva Lector is an entity in language school, that
 * represent lector. Admin can assign to him a Lecture.
 * @attribute ID lectors id, generated automatically, cannot be 0.
 * @attribute name name of lector. Must contain only small or large letters,
 * without punctation or special characters.
 * @attribute lectures list of lectures that a lector teaches. Lector can teach
 * 0..* lectures.
 * @levelofLanguage connection for languages and their difficulty
 */
@Entity
public class Lector implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private String surname;

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public List<LevelofLanguage> getLevelofLanguages() {
        return levelofLanguages;
    }

    public void setLevelofLanguages(List<LevelofLanguage> levelofLanguages) {
        this.levelofLanguages = levelofLanguages;
    }
    @OneToMany(mappedBy = "lector")
    private List<Lecture> lectures = new ArrayList<Lecture>();
    @OneToMany(mappedBy = "lector", orphanRemoval = true) //cascade=CascadeType.ALL)
    private List<LevelofLanguage> levelofLanguages = new ArrayList<LevelofLanguage>();

    public List<LevelofLanguage> getLevelofLanguage() {
        return levelofLanguages;
    }

    public void addLevelofLanguage(LevelofLanguage levofLang) {
        if (levelofLanguages != null) {
            levelofLanguages.add(levofLang);
        }
    }

    public void addLecture(Lecture lecture) {
        if (lectures != null) {
            lectures.add(lecture);
        }
    }

    public void setLevelofLanguage(List<LevelofLanguage> levelofLanguage) {
        this.levelofLanguages = levelofLanguage;
    }

    public List<Lecture> getLectures() {
        return lectures;
    }

    public void setLectures(List<Lecture> lectures) {
        this.lectures = lectures;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Lector)) {
            return false;
        }
        Lector other = (Lector) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        String str = "Lector[ id=" + id + ", name= " + name + ", surname " + surname;
        return str + " ]";
    }
}
